home *** CD-ROM | disk | FTP | other *** search
/ Almathera Ten Pack 3: CDPD 3 / Almathera Ten on Ten - Disc 3: CDPD3.iso / scope / scopedisk24 / Qrt14src / inout.c < prev    next >
C/C++ Source or Header  |  1988-08-23  |  24KB  |  1,116 lines

  1.  
  2. /**********************************************************
  3.  
  4.                     object loader language
  5.  
  6.  **********************************************************/
  7.  
  8. #define IODEBUG 1
  9.  
  10. #include "qrt.h"
  11. #include "pattern.h"
  12.  
  13. OBJ_PTR      new_obj(), Get_Object(), Get_Primitive(),
  14.              Get_Instance_Of();
  15. PATTERN_PTR  Attach_Pattern(), Get_Pattern();
  16. char         *malloc();
  17.  
  18. /**********************************************************
  19.  
  20.              External declarations from lexer
  21.  
  22.  **********************************************************/
  23.  
  24. float IsPos();
  25. float Get_Next_Num();
  26. short Get_Color_Val();
  27. char *Get_Next_Name();
  28.  
  29. float atof();
  30.  
  31.  
  32. /**********************************************************
  33.  
  34.    Global input line number.  If negative, error rountines
  35.    will not report line number (already reached EOF).
  36.  
  37.  **********************************************************/
  38.  
  39. extern int linenumber;
  40.  
  41. /**********************************************************
  42.  
  43.           Load the entire world from standard input
  44.  
  45.  **********************************************************/
  46.  
  47. int LoadWorld()                      /* load world from stdio */
  48. {
  49.   linenumber = 1;
  50.   if((THEWORLD.stack=Get_Object())==NULL)
  51.     Error(ILLEGAL_OBJECT,201);
  52.  
  53.   linenumber = -1;
  54.   return(TRUE);
  55. }
  56.  
  57. /**********************************************************
  58.  
  59.      Get an object and return a pointer to it. If it is
  60.      not an object, but some other world attribute
  61.      specification, note it, but keep trying until an
  62.      object is found or end of input is encountered.
  63.      This is slighly hacked out, but it works for now.
  64.      It calls itself recursively sometimes.
  65.  
  66.  **********************************************************/
  67.  
  68. OBJ_PTR Get_Object() {
  69.   char str[SLEN], *name;
  70.   OBJ_PTR newobj, queue, temp;
  71.   VECTOR loc,rad,d,v3, upper, lower;
  72.   CINFO cinfo;
  73.   int found;
  74.  
  75.   name=NULL; queue=NULL;
  76.   VectEqZero(&loc);
  77.   VectEqZero(&rad);
  78.   VectEqZero(&d);
  79.   VectEqZero(&v3);
  80.   VectEqZero(&upper);
  81.   VectEqZero(&lower);
  82.  
  83.   if (feof(stdin)) return(NULL);
  84.   while (!feof(stdin)) {
  85.     GetToken(str); found = FALSE;
  86.  
  87. #   ifdef IODEBUG
  88.       printf("GETOBJECT: token=%s\n",str);
  89. #   endif
  90.  
  91.     if (GetAttrib(str))
  92.       found = TRUE;
  93.  
  94.     if (strcmp(str,"BEGIN_INSTANCES")==0) {
  95.       found = TRUE;
  96.       THEWORLD.instances = Get_Object();
  97.     }
  98.  
  99.     if (strcmp(str,"END_INSTANCES")==0) {
  100. #     ifdef ROBUST
  101.         if (queue==NULL) Error(SYNTAX_ERROR,205);
  102. #     endif
  103.       found = TRUE;
  104.       return(queue);
  105.     }
  106.  
  107.     if (strcmp(str,"END_BBOX")==0) {
  108. #     ifdef ROBUST
  109.         if (queue==NULL) Error(SYNTAX_ERROR,206);
  110. #     endif
  111.       found = TRUE;
  112.       return(queue);
  113.     }
  114.  
  115.     if (strcmp(str,"BEGIN_BBOX")==0) {
  116.  
  117.        newobj=new_obj(BBOX,&loc,&rad,&d,&v3,&cinfo,NULL,NULL,name,
  118.                       &upper, &lower,
  119.                       (float)0.0, (float)0.0, (float)0.0);
  120.  
  121.        newobj->child = Get_Object();
  122.        newobj->nextobj = queue;
  123.        queue = newobj;
  124.        found = TRUE;
  125.  
  126.     }
  127.  
  128.     if (strcmp(str,"NAME")==0) {
  129.        name=Get_Next_Name();
  130.        found = TRUE;
  131.     }
  132.  
  133.     if ((temp=Get_Primitive(str))!=NULL) {
  134.       found = TRUE;
  135.       temp->nextobj=queue;
  136.       queue = temp;
  137.     }
  138.  
  139.     if (!found && !feof(stdin)) Error(SYNTAX_ERROR,207);
  140.  
  141.   }
  142.  
  143.   return(queue);
  144. }
  145.  
  146.  
  147. /**********************************************************
  148.  
  149.                  Load default color info
  150.  
  151.  **********************************************************/
  152.  
  153. def_colorinfo(cinfo)
  154.   CINFO_PTR cinfo;
  155. {
  156.   copy_colorinfo(cinfo,&(def.cinfo));
  157. }
  158.  
  159.  
  160. /**********************************************************
  161.  
  162.                     Copy color info
  163.  
  164.  **********************************************************/
  165.  
  166. copy_colorinfo(c1,c2)
  167.   CINFO_PTR c1,c2;
  168. {
  169.   if (c1 == NULL) return;
  170.  
  171.   SVectEQ(&(c1->amb),&(c2->amb));
  172.   SVectEQ(&(c1->diff),&(c2->diff));
  173.   SVectEQ(&(c1->mirror),&(c2->mirror));
  174.   SVectEQ(&(c1->trans),&(c2->trans));
  175.   VectEQ(&(c1->density),&(c2->density));
  176.  
  177.   c1->fuzz     = c2->fuzz;
  178.   c1->index    = c2->index;
  179.   c1->dither   = c2->dither;
  180.   c1->sreflect = c2->sreflect;
  181.   c1->reflect  = c2->reflect;
  182. }
  183.  
  184.  
  185. /**********************************************************
  186.  
  187.             Get defaults from input file
  188.  
  189.  **********************************************************/
  190.  
  191. int Get_Default()
  192. {
  193.   char        str[SLEN];
  194.   int         end, found;
  195.  
  196.   end=0;
  197.  
  198.   GetLeftParen();
  199.  
  200.   while (!end && !feof(stdin)) {
  201.     GetToken(str);
  202.  
  203. #   ifdef IODEBUG
  204.       printf("GETDEFAULT : token=%s\n",str);
  205. #   endif
  206.  
  207.     found = GetOpt(str,&(def.cinfo));
  208.  
  209.     if (strcmp(str,"NO_SHADOW")==0) {
  210.       def.shadow = FALSE;
  211.       found = TRUE;
  212.     }
  213.  
  214.     if (strcmp(str,"NO_LAMP")==0) {
  215.       def.vlamp = FALSE;
  216.       found = TRUE;
  217.     }
  218.  
  219.     if (strcmp(str,"THRESHOLD")==0) {
  220.       def.threshold = IsPos(Get_Next_Num());
  221.       found = TRUE;
  222.     }
  223.  
  224.     if (strcmp(str,")")==0) { end = 1; found = TRUE;}
  225.  
  226.     if (!found) Error(UNDEFINED_PARAM,209);
  227.   }
  228.   return(TRUE);
  229. }
  230.  
  231.  
  232. /**********************************************************
  233.  
  234.                     Get object options
  235.  
  236.  **********************************************************/
  237.  
  238. int GetOpt(str,cinfo)
  239.   char str[];
  240.   CINFO_PTR cinfo;
  241. {
  242.   int found;
  243.  
  244.   found = FALSE;
  245.  
  246.   if (strcmp(str,"AMB")==0) {
  247.     GetSVector(&(cinfo->amb));
  248.     found = TRUE;
  249.   }
  250.  
  251.   if (strcmp(str,"DIFF")==0) {
  252.     GetSVector(&(cinfo->diff));
  253.     found = TRUE;
  254.   }
  255.  
  256.   if (strcmp(str,"MIRROR")==0) {
  257.     GetSVector(&(cinfo->mirror));
  258.     found = TRUE;
  259.   }
  260.  
  261.   if (strcmp(str,"TRANS")==0) {
  262.     GetSVector(&(cinfo->trans));
  263.     found = TRUE;
  264.   }
  265.  
  266.   if (strcmp(str,"DENSITY")==0) {
  267.     GetVector(&(cinfo->density));
  268.     found = TRUE;
  269.   }
  270.  
  271.   if (strcmp(str,"FUZZ")==0) {
  272.     cinfo->fuzz     = Get_Color_Val();
  273.     found = TRUE;
  274.   }
  275.  
  276.   if (strcmp(str,"INDEX")==0) {
  277.     cinfo->index    = IsPos(Get_Next_Num());
  278.     found = TRUE;
  279.   }
  280.   if (strcmp(str,"DITHER")==0) {
  281.     cinfo->dither   = (short)IsPos(Get_Next_Num());
  282.     found = TRUE;
  283.   }
  284.   if (strcmp(str,"SREFLECT")==0) {
  285.     cinfo->sreflect = IsPos(Get_Next_Num());
  286.     found = TRUE;
  287.   }
  288.   if (strcmp(str,"REFLECT")==0) {
  289.     cinfo->reflect = Get_Color_Val();
  290.     found = TRUE;
  291.   }
  292.  
  293.   return(found);
  294. }
  295.  
  296.  
  297. /**********************************************************
  298.  
  299.           Load a sphere and return pointer to it
  300.  
  301.  **********************************************************/
  302.  
  303. OBJ_PTR GetSphere()
  304. {
  305.   char        str[SLEN], *name;
  306.   VECTOR      loc, rad, d, v3, upper, lower;
  307.   float       xmult, ymult;
  308.   CINFO       cinfo;
  309.   OBJ_PTR     newobj;
  310.   PATTERN_PTR pattern, remove;
  311.   int         end, f, found;
  312.  
  313.   end=f=0;
  314.   def_colorinfo(&cinfo);
  315.   xmult=ymult=1;
  316.   pattern = remove = NULL;
  317.   name    = NULL;
  318.  
  319.   GetLeftParen();
  320.  
  321.   while (!end && !feof(stdin)) {
  322.     GetToken(str);
  323.  
  324. #   ifdef IODEBUG
  325.       printf("GETSPHERE : token=%s\n",str);
  326. #   endif
  327.  
  328.     found = GetOpt(str,&cinfo);
  329.  
  330.     if ((strcmp(str,"POS")==0)      ||
  331.         (strcmp(str,"LOC")==0)      ||
  332.         (strcmp(str,"POSITION")==0) ||
  333.         (strcmp(str,"LOCATION")==0)) {
  334.  
  335.       GetVector(&loc);
  336.       f|=1; found = TRUE;
  337.     }
  338.  
  339.     if (strcmp(str,"RADIUS")==0) {
  340.       rad.x = IsPos(Get_Next_Num());
  341.       f|=2; found = TRUE;
  342.     }
  343.     if (strcmp(str,"PATTERN")==0) {
  344.       pattern = Attach_Pattern();
  345.       found = TRUE;
  346.     }
  347.     if (strcmp(str,"REMOVE")==0) {
  348.       remove = Attach_Pattern();
  349.       found = TRUE;
  350.     }
  351.     if (strcmp(str,"XMULT")==0) {
  352.       xmult = IsPos(Get_Next_Num());
  353.       found=TRUE;
  354.     }
  355.     if (strcmp(str,"YMULT")==0) {
  356.       ymult = IsPos(Get_Next_Num());
  357.       found=TRUE;
  358.     }
  359.     if (strcmp(str,"NAME")==0) {
  360.        name=Get_Next_Name();
  361.        found = TRUE;
  362.     }
  363.  
  364.     if (strcmp(str,")")==0) { end = 1; found = TRUE; }
  365.  
  366.     if (!found) Error(UNDEFINED_PARAM,211);
  367.   }
  368.  
  369.   if (f!=3) Error(TOO_FEW_PARMS,212);
  370.   rad.y=rad.z=0;
  371.  
  372.   VectEqZero(&d);
  373.   VectEqZero(&upper);
  374.   VectEqZero(&lower);
  375.  
  376.   newobj=new_obj(SPHERE,&loc,&rad,&d,&v3,&cinfo,pattern,
  377.                  remove,name,
  378.                  &upper, &lower, 0.0, xmult, ymult);
  379.  
  380.   THEWORLD.objcount++;
  381.   return(newobj);
  382. }
  383.  
  384.  
  385. /**********************************************************
  386.  
  387.              Load lamp and attach to world
  388.  
  389.  **********************************************************/
  390.  
  391. int GetLamp()
  392. {
  393.   char str[SLEN];
  394.   VECTOR loc, rad, d, v3, upper, lower;
  395.   CINFO cinfo;
  396.   int   end, f, found;
  397.  
  398.   end=f=0;
  399.  
  400.   cinfo.amb.r=cinfo.amb.g=cinfo.amb.b=CNUM;
  401.   rad.y=150;
  402.  
  403.   GetLeftParen();
  404.  
  405.   while (!end && !feof(stdin)) {
  406.     GetToken(str); found = TRUE;
  407.  
  408. #   ifdef IODEBUG
  409.       printf("GETLAMP : token=%s\n",str);
  410. #   endif
  411.  
  412.     found = GetOpt(str,&cinfo);
  413.  
  414.     if ((strcmp(str,"POS")==0)      ||
  415.         (strcmp(str,"LOC")==0)      ||
  416.         (strcmp(str,"POSITION")==0) ||
  417.         (strcmp(str,"LOCATION")==0)) {
  418.  
  419.       GetVector(&loc);
  420.       f|=1; found = TRUE;
  421.     }
  422.  
  423.     if (strcmp(str,"RADIUS")==0) {
  424.       rad.x = IsPos(Get_Next_Num());
  425.       f|=2; found = TRUE;
  426.     }
  427.     if (strcmp(str,"DIST")==0) {
  428.       rad.y = IsPos(Get_Next_Num());
  429.       f|=4; found = TRUE;
  430.     }
  431.     if (strcmp(str,")")==0) { end = 1; found = TRUE;}
  432.  
  433.     if (!found) Error(UNDEFINED_PARAM,214);
  434.   }
  435.  
  436.   if (f!=7) return(FALSE);
  437.  
  438.   rad.z=0;
  439.  
  440.   VectEqZero(&d);
  441.   VectEqZero(&v3);
  442.   VectEqZero(&upper);
  443.   VectEqZero(&lower);
  444.  
  445.   cinfo.diff.r=cinfo.diff.g=cinfo.diff.b=CNUM;
  446.  
  447.   add_lamp(new_obj(LAMP,&loc,&rad,&d,&v3,&cinfo,NULL,NULL,
  448.                    NULL, &upper, &lower,
  449.                    (float)0.0, (float)0.0, (float)0.0));
  450.  
  451.   THEWORLD.lampcount++;
  452.   return(TRUE);
  453. }
  454.  
  455.  
  456. /**********************************************************
  457.  
  458.          Load observer and attach him to the world
  459.  
  460.  **********************************************************/
  461.  
  462. int GetObserver()
  463. {
  464.   char   str[SLEN];
  465.   VECTOR loc, lk, up, dir, v3, upper, lower;
  466.   CINFO  cinfo;
  467.   int    end, f, found;
  468.  
  469.   end=f=0;
  470.   up.x = up.z = 0; up.y = 1;
  471.  
  472.   GetLeftParen();
  473.  
  474.   while (!end && !feof(stdin)) {
  475.     GetToken(str); found = FALSE;
  476.  
  477. #   ifdef IODEBUG
  478.       printf("GETOBSERVER : token=%s\n",str);
  479. #   endif
  480.  
  481.     if ((strcmp(str,"POS")==0)      ||
  482.         (strcmp(str,"LOC")==0)      ||
  483.         (strcmp(str,"POSITION")==0) ||
  484.         (strcmp(str,"LOCATION")==0)) {
  485.  
  486.       GetVector(&loc);
  487.       f|=1; found = TRUE;
  488.     }
  489.  
  490.     if (strcmp(str,"LOOKAT")==0) {
  491.       GetVector(&lk);
  492.       f|=2; found = TRUE;
  493.     }
  494.  
  495.     if (strcmp(str,"UP")==0) {
  496.       GetVector(&up);
  497.       found = TRUE;
  498.     }
  499.  
  500.     if (strcmp(str,")")==0) { end = 1; found = TRUE; }
  501.  
  502.     if (!found) Error(UNDEFINED_PARAM,216);
  503.   }
  504.  
  505.   VecSubtract(&dir,&lk,&loc);    /* find view direction */
  506.  
  507.   VectEqZero(&v3);
  508.   VectEqZero(&upper);
  509.   VectEqZero(&lower);
  510.  
  511.   if (f!=3) Error(TOO_FEW_PARMS,217);
  512.  
  513.   THEWORLD.observer=
  514.      new_obj(OBSERVER,&loc,&dir,&up,&v3,&cinfo,NULL,NULL,
  515.              NULL, &upper, &lower,
  516.              (float)0.0, (float)0.0, (float)0.0);
  517.  
  518.   return(TRUE);
  519. }
  520.  
  521.  
  522. /**********************************************************
  523.  
  524.           Load triangle  - not yet implimented
  525.  
  526.  **********************************************************/
  527.  
  528. OBJ_PTR GetTriangle()
  529. {
  530.   char        str[SLEN], *name;
  531.   CINFO       cinfo;
  532.   VECTOR      loc, v1, v2, v3, upper, lower;
  533.   OBJ_PTR     newobj;
  534.   PATTERN_PTR pattern, remove;
  535.   int         end, f, found;
  536.   float       xmult, ymult;
  537.  
  538.   end=f=0;
  539.   xmult=ymult=1;
  540.   def_colorinfo(&cinfo);
  541.   pattern = remove = NULL;
  542.   name    = NULL;
  543.  
  544.   GetLeftParen();
  545.  
  546.   while (!end && !feof(stdin)) {
  547.     GetToken(str);
  548.  
  549. #   ifdef IODEBUG
  550.       printf("GETTRIANGLE : token=%s\n",str);
  551. #   endif
  552.  
  553.     found = GetOpt(str,&cinfo);
  554.  
  555.     if ((strcmp(str,"POS")==0)      ||
  556.         (strcmp(str,"LOC")==0)      ||
  557.         (strcmp(str,"POSITION")==0) ||
  558.         (strcmp(str,"LOCATION")==0)) {
  559.  
  560.       GetVector(&loc);
  561.       f|=1; found = TRUE;
  562.     }
  563.  
  564.     if ((strcmp(str,"V1")==0)     ||
  565.         (strcmp(str,"VECT1")==0)) {
  566.  
  567.       GetVector(&v1);
  568.       f|=2; found = TRUE;
  569.     }
  570.  
  571.     if ((strcmp(str,"V2")==0)     ||
  572.         (strcmp(str,"VECT2")==0)) {
  573.  
  574.       GetVector(&v2);
  575.       f|=4; found = TRUE;
  576.     }
  577.  
  578.     if (strcmp(str,"PATTERN")==0) {
  579.       pattern=Attach_Pattern();
  580.       found = TRUE;
  581.     }
  582.     if (strcmp(str,"REMOVE")==0) {
  583.       remove=Attach_Pattern();
  584.       found = TRUE;
  585.     }
  586.  
  587.     if (strcmp(str,"XMULT")==0) {
  588.       xmult = IsPos(Get_Next_Num());
  589.       found=TRUE;
  590.     }
  591.     if (strcmp(str,"YMULT")==0) {
  592.       ymult = IsPos(Get_Next_Num());
  593.       found=TRUE;
  594.     }
  595.     if (strcmp(str,"NAME")==0) {
  596.        name=Get_Next_Name();
  597.        found = TRUE;
  598.     }
  599.  
  600.     if (strcmp(str,")")==0) { end = 1; found = TRUE;}
  601.  
  602.     if (!found) Error(UNDEFINED_PARAM,219);
  603.   }
  604.  
  605.   if (f!=7) Error(TOO_FEW_PARMS,220);
  606.  
  607.   VectEqZero(&v3);
  608.   VectEqZero(&upper);
  609.   VectEqZero(&lower);
  610.  
  611.   newobj=new_obj(TRIANGLE,&loc,&v1,&v2,&v3,&cinfo,pattern,
  612.                  remove, name,
  613.                  &upper, &lower, 0.0, xmult, ymult);
  614.  
  615.   THEWORLD.objcount++;
  616.   return(newobj);
  617. }
  618.  
  619.  
  620. /**********************************************************
  621.  
  622.          Load sky data and attach it to the world
  623.  
  624.  **********************************************************/
  625.  
  626. int GetSky()
  627. {
  628.   VECTOR loc, v1, v2, v3, upper, lower;
  629.   CINFO  cinfo;
  630.   char   str[SLEN];
  631.   int    end, found;
  632.  
  633.   end=0;
  634.   GetLeftParen();
  635.  
  636.   def_colorinfo(&cinfo);
  637.  
  638.   while (!end && !feof(stdin)) {
  639.     GetToken(str);
  640.  
  641.     found = GetOpt(str,&cinfo);                    /*** DITHER ONLY ***/
  642.  
  643.     if (strcmp(str,"ZENITH")==0) {
  644.        GetSVector(&(THEWORLD.skycolor_zenith));
  645.        found = TRUE;
  646.     }
  647.  
  648.     if ((strcmp(str,"HORIZ")==0) ||
  649.         (strcmp(str,"HORIZON")==0)) {
  650.  
  651.        GetSVector(&(THEWORLD.skycolor_horiz));
  652.        found = TRUE;
  653.     }
  654.     if (strcmp(str,")")==0) { end=1; found=TRUE; }
  655.  
  656.     if (!found) Error(UNDEFINED_PARAM,222);
  657.   }
  658.  
  659.   VectEqZero(&v3);
  660.   VectEqZero(&upper);
  661.   VectEqZero(&lower);
  662.  
  663.   THEWORLD.sky=new_obj(SKY,&loc,&v1,&v2,&v3,&cinfo,NULL,NULL,
  664.                        NULL, &upper, &lower,
  665.                        (float)0.0, (float)0.0, (float)0.0);
  666.   return(TRUE);
  667. }
  668.  
  669. /**********************************************************
  670.  
  671.             Load ring and return pointer to it
  672.  
  673.  **********************************************************/
  674.  
  675. OBJ_PTR GetRing()
  676. {
  677.   char        str[SLEN], *name;
  678.   CINFO       cinfo;
  679.   VECTOR      loc, v1, v2, v3, upper, lower;
  680.   OBJ_PTR     newobj;
  681.   PATTERN_PTR pattern, remove;
  682.   int         end, f, found;
  683.   float       xmult, ymult;
  684.  
  685.   end=f=0;
  686.   xmult=ymult=1;
  687.   def_colorinfo(&cinfo);
  688.   pattern = remove = NULL;
  689.   name    = NULL;
  690.  
  691.   GetLeftParen();
  692.  
  693.   while (!end && !feof(stdin)) {
  694.     GetToken(str);
  695.  
  696. #   ifdef IODEBUG
  697.       printf("GETRING : token=%s\n",str);
  698. #   endif
  699.  
  700.     found = GetOpt(str,&cinfo);
  701.  
  702.     if ((strcmp(str,"POS")==0)      ||
  703.         (strcmp(str,"LOC")==0)      ||
  704.         (strcmp(str,"POSITION")==0) ||
  705.         (strcmp(str,"LOCATION")==0)) {
  706.  
  707.       GetVector(&loc);
  708.       f|=1; found = TRUE;
  709.     }
  710.  
  711.     if ((strcmp(str,"V1")==0)     ||
  712.         (strcmp(str,"VECT1")==0)) {
  713.  
  714.       GetVector(&v1);
  715.       f|=2; found = TRUE;
  716.     }
  717.  
  718.     if ((strcmp(str,"V2")==0)     ||
  719.         (strcmp(str,"VECT2")==0)) {
  720.  
  721.       GetVector(&v2);
  722.       f|=4; found = TRUE;
  723.     }
  724.  
  725.     if (strcmp(str,"RAD_1")==0) {
  726.        v3.x = IsPos(Get_Next_Num());
  727.        f|=8; found = TRUE;
  728.     }
  729.     if (strcmp(str,"RAD_2")==0) {
  730.        v3.y = IsPos(Get_Next_Num());
  731.        f|=16; found = TRUE;
  732.     }
  733.     if (strcmp(str,"PATTERN")==0) {
  734.        pattern=Attach_Pattern();
  735.        found = TRUE;
  736.     }
  737.     if (strcmp(str,"REMOVE")==0) {
  738.       remove=Attach_Pattern();
  739.       found = TRUE;
  740.     }
  741.     if (strcmp(str,"XMULT")==0) {
  742.       xmult = IsPos(Get_Next_Num());
  743.       found=TRUE;
  744.     }
  745.     if (strcmp(str,"YMULT")==0) {
  746.       ymult = IsPos(Get_Next_Num());
  747.       found=TRUE;
  748.     }
  749.     if (strcmp(str,"NAME")==0) {
  750.        name=Get_Next_Name();
  751.        found = TRUE;
  752.     }
  753.  
  754.     if (strcmp(str,")")==0) { end = 1; found = TRUE; }
  755.  
  756.     if (!found) Error(UNDEFINED_PARAM,224);
  757.   }
  758.  
  759.   if (f!=31) Error(TOO_FEW_PARMS,225);
  760.   v3.z = 0;
  761.   Normalize(&v1);
  762.   Normalize(&v2);
  763.  
  764.   newobj=new_obj(RING,&loc,&v1,&v2,&v3,&cinfo,pattern,
  765.                  remove, name,
  766.                  &upper, &lower, 0.0, xmult, ymult);
  767.  
  768.   THEWORLD.objcount++;
  769.   return(newobj);
  770. }
  771.  
  772.  
  773. /**********************************************************
  774.  
  775.        Load parallelogram and return pointer to it
  776.  
  777.  **********************************************************/
  778.  
  779. OBJ_PTR GetParallelogram()
  780. {
  781.   char        str[SLEN], *name;
  782.   CINFO       cinfo;
  783.   VECTOR      loc, v1, v2, v3, upper, lower;
  784.   OBJ_PTR     newobj;
  785.   PATTERN_PTR pattern, remove;
  786.   int         end, f, found;
  787.   float       xmult, ymult;
  788.  
  789.   end=f=0;
  790.   xmult=ymult=1;
  791.   def_colorinfo(&cinfo);
  792.   pattern = remove = NULL;
  793.   name    = NULL;
  794.  
  795.   GetLeftParen();
  796.  
  797.   while (!end && !feof(stdin)) {
  798.     GetToken(str);
  799.  
  800. #   ifdef IODEBUG
  801.       printf("GETPARREL : token=%s\n",str);
  802. #   endif
  803.  
  804.     found = GetOpt(str,&cinfo);
  805.  
  806.     if ((strcmp(str,"POS")==0)      ||
  807.         (strcmp(str,"LOC")==0)      ||
  808.         (strcmp(str,"POSITION")==0) ||
  809.         (strcmp(str,"LOCATION")==0)) {
  810.  
  811.       GetVector(&loc);
  812.       f|=1; found = TRUE;
  813.     }
  814.  
  815.     if ((strcmp(str,"V1")==0)     ||
  816.         (strcmp(str,"VECT1")==0)) {
  817.  
  818.       GetVector(&v1);
  819.       f|=2; found = TRUE;
  820.     }
  821.  
  822.     if ((strcmp(str,"V2")==0)     ||
  823.         (strcmp(str,"VECT2")==0)) {
  824.  
  825.       GetVector(&v2);
  826.       f|=4; found = TRUE;
  827.     }
  828.  
  829.     if (strcmp(str,"PATTERN")==0) {
  830.       pattern=Attach_Pattern();
  831.       found = TRUE;
  832.     }
  833.     if (strcmp(str,"REMOVE")==0) {
  834.       remove=Attach_Pattern();
  835.       found = TRUE;
  836.     }
  837.  
  838.     if (strcmp(str,"XMULT")==0) {
  839.       xmult = IsPos(Get_Next_Num());
  840.       found=TRUE;
  841.     }
  842.     if (strcmp(str,"YMULT")==0) {
  843.       ymult = IsPos(Get_Next_Num());
  844.       found=TRUE;
  845.     }
  846.     if (strcmp(str,"NAME")==0) {
  847.        name=Get_Next_Name();
  848.        found = TRUE;
  849.     }
  850.  
  851.     if (strcmp(str,")")==0) { end = 1; found = TRUE;}
  852.  
  853.     if (!found) Error(UNDEFINED_PARAM,227);
  854.   }
  855.  
  856.   if (f!=7) Error(TOO_FEW_PARMS,228);
  857.  
  858.   VectEqZero(&v3);
  859.   VectEqZero(&upper);
  860.   VectEqZero(&lower);
  861.  
  862.   newobj=new_obj(PARALLELOGRAM,&loc,&v1,&v2,&v3,&cinfo,
  863.                  pattern, remove,name,
  864.                  &upper, &lower, 0.0, xmult, ymult);
  865.  
  866.   THEWORLD.objcount++;
  867.   return(newobj);
  868. }
  869.  
  870. /**********************************************************
  871.  
  872.                   Load quadratic surface
  873.  
  874.  **********************************************************/
  875.  
  876. OBJ_PTR GetQuadratic()
  877. {
  878.   char        str[SLEN], *name;
  879.   CINFO       cinfo;
  880.   VECTOR      loc, v1, v2, v3, upper, lower;
  881.   OBJ_PTR     newobj;
  882.   PATTERN_PTR pattern, remove;
  883.   int         end, f, found;
  884.   float       cterm, xmult, ymult;
  885.  
  886.   end=f=0;
  887.   xmult=ymult=1;
  888.   def_colorinfo(&cinfo);
  889.   pattern = remove = NULL;
  890.   name    = NULL;
  891.  
  892.   GetLeftParen();
  893.  
  894.   upper.x = upper.y = upper.z = 10;
  895.   lower.x = lower.y = lower.z = -10;
  896.  
  897.   v1.x = 0; v1.y = 1; v1.z = 0;
  898.  
  899.   while (!end && !feof(stdin)) {
  900.     GetToken(str);
  901.  
  902. #   ifdef IODEBUG
  903.       printf("GETQUAD : token=%s\n",str);
  904. #   endif
  905.  
  906.     found = GetOpt(str,&cinfo);
  907.  
  908.     if ((strcmp(str,"POS")==0)      ||
  909.         (strcmp(str,"LOC")==0)      ||
  910.         (strcmp(str,"POSITION")==0) ||
  911.         (strcmp(str,"LOCATION")==0)) {
  912.  
  913.       GetVector(&loc);
  914.       f|=1; found = TRUE;
  915.     }
  916.  
  917.     if (strcmp(str,"A")==0) {
  918.       v2.x  = Get_Next_Num();
  919.       f|=2; found = TRUE;
  920.     }
  921.     if (strcmp(str,"B")==0) {
  922.       v2.y  = Get_Next_Num();
  923.       f|=4; found = TRUE;
  924.     }
  925.     if (strcmp(str,"C")==0) {
  926.       v2.z  = Get_Next_Num();
  927.       f|=8; found = TRUE;
  928.     }
  929.     if (strcmp(str,"D")==0) {
  930.       cterm = Get_Next_Num();
  931.       f|=16; found = TRUE;
  932.     }
  933.  
  934.     if (strcmp(str,"XMIN")==0) {
  935.       lower.x  = Get_Next_Num();
  936.       found    = TRUE;
  937.     }
  938.     if (strcmp(str,"XMAX")==0) {
  939.       upper.x  = Get_Next_Num();
  940.       found    = TRUE;
  941.     }
  942.     if (strcmp(str,"YMIN")==0) {
  943.       lower.y  = Get_Next_Num();
  944.       found    = TRUE;
  945.     }
  946.     if (strcmp(str,"YMAX")==0) {
  947.       upper.y  = Get_Next_Num();
  948.       found    = TRUE;
  949.     }
  950.     if (strcmp(str,"ZMIN")==0) {
  951.       lower.z  = Get_Next_Num();
  952.       found    = TRUE;
  953.     }
  954.     if (strcmp(str,"ZMAX")==0) {
  955.       upper.z  = Get_Next_Num();
  956.       found    = TRUE;
  957.     }
  958.  
  959.     if (strcmp(str,"DIR")==0) {
  960.       GetVector(&v1);
  961.       found = TRUE;
  962.     }
  963.  
  964.     if (strcmp(str,"PATTERN")==0) {
  965.       pattern=Attach_Pattern();
  966.       found = TRUE;
  967.     }
  968.     if (strcmp(str,"REMOVE")==0) {
  969.       remove=Attach_Pattern();
  970.       found = TRUE;
  971.     }
  972.     if (strcmp(str,"XMULT")==0) {
  973.       xmult = IsPos(Get_Next_Num());
  974.       found=TRUE;
  975.     }
  976.     if (strcmp(str,"YMULT")==0) {
  977.       ymult = IsPos(Get_Next_Num());
  978.       found=TRUE;
  979.     }
  980.     if (strcmp(str,"NAME")==0) {
  981.        name=Get_Next_Name();
  982.        found = TRUE;
  983.     }
  984.  
  985.     if (strcmp(str,")")==0) { end = 1; found = TRUE;}
  986.  
  987.     if (!found) Error(UNDEFINED_PARAM,230);
  988.   }
  989.  
  990.   if (f!=31) Error(TOO_FEW_PARMS,231);
  991.  
  992.   VectEqZero(&v3);
  993.  
  994.   newobj=new_obj(QUADRATIC,&loc,&v1,&v2,&v3,&cinfo,pattern,
  995.                  remove, name,
  996.                  &upper, &lower, cterm, xmult, ymult);
  997.  
  998.   THEWORLD.objcount++;
  999.   return(newobj);
  1000. }
  1001.  
  1002.  
  1003. /**********************************************************
  1004.  
  1005.        Load the focal length of the observers lens
  1006.  
  1007.  **********************************************************/
  1008.  
  1009. int GetFocLength() {
  1010.   THEWORLD.flength=IsPos(Get_Next_Num());
  1011.   return(TRUE);
  1012. }
  1013.  
  1014.  
  1015. /**********************************************************
  1016.  
  1017.     Load a primitive from input and return pointer to it
  1018.  
  1019.  **********************************************************/
  1020.  
  1021. OBJ_PTR Get_Primitive(str)                /* get an object */
  1022.   char str[];
  1023. {
  1024.   OBJ_PTR newobj;
  1025.  
  1026. # ifdef IODEBUG
  1027.     printf("GETPRIMITIVE : token=%s:\n",str);
  1028. # endif
  1029.  
  1030.   newobj=NULL;
  1031.   if (strcmp(str,"SPHERE")==0) {
  1032.     if ((newobj=GetSphere())==NULL)
  1033.       Error(ILLEGAL_OBJECT,232);
  1034.   }
  1035.   if (strcmp(str,"PARALLELOGRAM")==0) {
  1036.     if ((newobj=GetParallelogram())==NULL)
  1037.       Error(ILLEGAL_OBJECT,233);
  1038.   }
  1039.   if (strcmp(str,"TRIANGLE")==0) {
  1040.     if ((newobj=GetTriangle())==NULL)
  1041.       Error(ILLEGAL_OBJECT,234);
  1042.   }
  1043.   if (strcmp(str,"RING")==0) {
  1044.     if ((newobj=GetRing())==NULL)
  1045.       Error(ILLEGAL_OBJECT,235);
  1046.   }
  1047.   if (strcmp(str,"QUADRATIC")==0) {
  1048.     if ((newobj=GetQuadratic())==NULL)
  1049.       Error(ILLEGAL_OBJECT,236);
  1050.   }
  1051.   if (strcmp(str,"INSTANCE_OF")==0) {
  1052.     if ((newobj=Get_Instance_Of())==NULL)
  1053.       Error(ILLEGAL_OBJECT,237);
  1054.   }
  1055.   return(newobj);
  1056. }
  1057.  
  1058.  
  1059. /**********************************************************
  1060.  
  1061.      Load an attribute from input and do stuff with it
  1062.  
  1063.  **********************************************************/
  1064.  
  1065. int GetAttrib(str)                    /* get an object */
  1066.   char str[];
  1067. {
  1068.   int found;
  1069.  
  1070.   found=FALSE;
  1071.  
  1072. # ifdef IODEBUG
  1073.     printf("GETATTRIB : token=%s:\n",str);
  1074. # endif
  1075.  
  1076.   if (strcmp(str,"SKY")==0) {
  1077.     if (!GetSky())      Error(INTERNAL_ERROR,238);
  1078.     found=TRUE;
  1079.   }
  1080.   if (strcmp(str,"FOC_LENGTH")==0) {
  1081.     if (!GetFocLength()) Error(INTERNAL_ERROR,239);
  1082.     found=TRUE;
  1083.   }
  1084.   if (strcmp(str,"FIRST_SCAN")==0) {
  1085.     THEWORLD.first_scan=(int)IsPos(Get_Next_Num());
  1086.     found=TRUE;
  1087.   }
  1088.   if (strcmp(str,"DEFAULT")==0) {
  1089.     if (!Get_Default()) Error(INTERNAL_ERROR,240);
  1090.     found=TRUE;
  1091.   }
  1092.   if (strcmp(str,"FILE_NAME")==0) {
  1093.     THEWORLD.outfile=Get_Next_Name();
  1094.     found=TRUE;
  1095.   }
  1096.   if (strcmp(str,"LAMP")==0) {
  1097.     if (!GetLamp())     Error(INTERNAL_ERROR,241);
  1098.     found=TRUE;
  1099.   }
  1100.   if (strcmp(str,"OBSERVER")==0) {
  1101.     if (!GetObserver()) Error(INTERNAL_ERROR,242);
  1102.     found=TRUE;
  1103.   }
  1104.   if (strcmp(str,"LAST_SCAN")==0) {
  1105.     THEWORLD.last_scan=(int)IsPos(Get_Next_Num());
  1106.     found=TRUE;
  1107.   }
  1108.   if (strcmp(str,"PATTERN")==0) {
  1109.     if (!GetPattern())  Error(INTERNAL_ERROR,243);
  1110.     found=TRUE;
  1111.   }
  1112.  
  1113.   return(found);
  1114. }
  1115.  
  1116.